<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="buildingList_content/css/main.css">
    </head>
    <body class="um-vp bc-bg" ontouchstart>
        <div class="umar-h1 c-wh ubr ubl ubt b-gra" id="sortList"></div>
        <div class="umh1"></div>
        <script src="js/appcan.js"></script>
        <script src="js/appcan.control.js"></script>
        <script src="js/appcan.listview.js"></script>
    </body>
    <script>
        appcan.ready(function() {
            appcan.initBounce();
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/get_buildings',
                data : {},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    if (data.state == 0)
                    {
                        init_building(data.buildings);
                        sortList();
                    }
                },
                error:function(){
                    alert("fuck");
                }
            })
        })
        var arrData = [];
        function init_building(buildings)
        {
            var len = buildings.length;
            for(var i = 0; i < len; ++i)
            {
                arrData.push({
                    "title" : buildings[i].name,
                    "id" : buildings[i].id,
                    "louzhang" : buildings[i].louzhang,
                });
            }
            localStorage.setItem('buildings',arrData);
        }
        function sortList() {
            
            var listData = [];
            var len = arrData.length;
            for (var i = 0; i < len; i++) {
                var list = {
                    title : arrData[i].title,
                    build_id : arrData[i].id,
                    louzhang : arrData[i].louzhang,
                }
                listData.push(list);

            }
            var lv1 = appcan.listview({
                selector : "#sortList",
                type : "thinLine",
                hasIcon : false,
                hasAngle : true,
                hasSubTitle : false,
                multiLine : 1,
                hasCheckbox : false,
                align : 'left'
            });
            lv1.set(listData);
            lv1.on('click', function(ele, context, obj, subobj) {
                localStorage.setItem('build_id',context.build_id);
                localStorage.setItem('build_name',context.title);
                appcan.openWinWithUrl('info', 'info.html');
            })
        }

    </script>
</html>
